package com.crane.oss.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;


@Configuration
@EnableSwagger2
//@ConditionalOnProperty(prefix = "swagger2", value = {"enable"}, havingValue = "true")
public class Swagger2 {

    @Bean
    public Docket createSysApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("系统管理接口").apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.crane.oss.web.controller.sys"))
                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
    }

    @Bean
    public Docket createSchoolApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("学校基础信息管理").apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.crane.oss.web.controller.school"))
                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
    }

//    @Bean
//    public Docket createCommonApi() {
//        return new Docket(DocumentationType.SWAGGER_2).groupName("API接口").apiInfo(apiInfo()).select()
//                .apis(RequestHandlerSelectors.basePackage("com.crane.oss.web.controller.api"))
//                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
//    }

    @Bean
    public Docket createSportsApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("智慧体育课堂").apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.crane.oss.web.controller.sports"))
                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
    }

//    @Bean
//    public Docket createAppApi() {
//        return new Docket(DocumentationType.SWAGGER_2).groupName("App接口").apiInfo(apiInfo()).select()
//                .apis(RequestHandlerSelectors.basePackage("com.crane.app.web.controller"))
//                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
//    }

//    @Bean
//    public Docket createEpcApi() {
//        return new Docket(DocumentationType.SWAGGER_2).groupName("业务管理接口").apiInfo(apiInfo()).select()
//                .apis(RequestHandlerSelectors.basePackage("com.crane.oss.web.controller.epc"))
//                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
//    }

//    @Bean
//    public Docket createReportApi() {
//        return new Docket(DocumentationType.SWAGGER_2).groupName("报表管理接口").apiInfo(apiInfo()).select()
//                .apis(RequestHandlerSelectors.basePackage("com.crane.oss.web.controller.report"))
//                .paths(PathSelectors.any()).build().globalOperationParameters(bulidParameter());
//    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("接口管理").description("接口描述")
                .contact(new Contact("bealon", "ccsu123456@qq.com", "ccsu123456@qq.com")).version("1.0").build();
    }

    private List<Parameter> bulidParameter() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder debugPar = new ParameterBuilder();
        debugPar.name("X-AUTH-SESSION").hidden(true).description("token选项").modelRef(new ModelRef("string")).parameterType("header").defaultValue("").build();

        ParameterBuilder debugPar1 = new ParameterBuilder();
        pars.add(debugPar.build());
        return pars;
    }

}
